import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';


// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    proxy: {
      '/dev': {
        target: 'https://apis.netstart.cn/haokan/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev/, ''),
      },
      '/proxy-image': {
        target: 'http://ksyuncomic.9comic.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/proxy-image/, ''),
        headers: {
          Referer: 'http://ksyuncomic.9comic.cn', // 设置合法的 Referer
        }
      },
      '/proxy-ad': {
        target: 'https://www.yzpai.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/proxy-ad/, ''),
        headers: {
          Referer: 'https://www.yzpai.cn/', // 设置合法的 Referer
        }
      },

    },
  },
  esbuild: {
    drop: ['console', 'debugger'],
  }
})
